package com.by.controller;

import com.by.common.bean.ResultBean;
import com.by.common.controller.BaseController;
import com.by.pojo.entity.Dict;
import com.by.pojo.entity.play;
import com.by.pojo.entity.temp;
import com.by.service.DictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
@Api(tags = "字典接口")
public class DictController extends BaseController {

    private final DictService dictService;

    @Autowired
    public DictController(DictService dictService) {
        this.dictService = dictService;
    }

    @ApiOperation("保存字典")
    @PostMapping("/dict")
    public ResultBean save(@RequestBody Dict dict) {
        int ans = dictService.save(dict);
        return saveResult(ans);
    }


    /**
     * 根据pid查询字典
     *
     * @return
     */
    @ApiOperation("根据pid查询字典列表")
    @GetMapping("/dict")
    public ResultBean<List<Dict>> selectByPid(Integer pid) {
        List<Dict> dicts = dictService.selectByPid(pid);
        return success("字典列表", dicts);
    }


    /**
     * 修改字典
     *
     * @param dict
     * @return
     */
    @ApiOperation("修改字典")
    @PutMapping("/dict")
    public ResultBean update(@RequestBody Dict dict) {
        int ans = dictService.update(dict);
        return updateResult(ans);
    }

    @ApiOperation("删除字典")
    @DeleteMapping("/dict")
    public ResultBean delete(Integer id) {
        int ans = dictService.delete(id);
        return deleteResult(ans);
    }

    @ApiOperation("字典播放")
    @PostMapping("/dict/play")
    public ResultBean play(@RequestBody play map) {
        System.out.println(map.getClass());
        System.out.println(map.getLs());
        for (temp t : map.getLs()) {
            System.out.println(t.getClass());
            System.out.println(t.getId());
            System.out.println(t.getName());
        }
        return null;
    }


}
